//
//  LEReplyDetialController.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/25.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "LEReplyDetialController.h"
#import "LEReplyToupleCell.h"
#import "LEReplyContentCell.h"
#import "LEGoodsCell.h"
#import "LEReplyModel.h"
#import "LERemarkCell.h"
#import "LEExplainContentController.h"

static NSString *const LEReplyToupleCellId = @"LEReplyToupleCell";
static NSString *const LEReplyContentCellId = @"LEReplyContentCell";
static NSString *const LEGoodsCellId = @"LEGoodsCell";
static NSString *const LERemarkCellId = @"LERemarkCell";

@interface LEReplyDetialController ()

@end

@implementation LEReplyDetialController

- (void)setupUI
{
    [super setupUI];
    self.title = @"投诉详情";
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LEReplyToupleCell" bundle:nil] forCellReuseIdentifier:LEReplyToupleCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEReplyContentCell" bundle:nil] forCellReuseIdentifier:LEReplyContentCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEGoodsCell" bundle:nil] forCellReuseIdentifier:LEGoodsCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LERemarkCell" bundle:nil] forCellReuseIdentifier:LERemarkCellId];
    [self resetTablewFrame:CGRectMake(0, 0, LEScreenWidth, LEScreenHeight -64)];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshRemarkContent:) name:REMARK_NOTIFICATION object:nil];
}

#pragma mark- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return 5;
            break;
        case 1:
            return self.model.goodsModelArray.count;
            break;
        case 2:
            return 4;
            break;
        case 3:
            return 1;
            break;
            
        default:
            return 1;
            break;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 45;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, LEScreenWidth, 45)];
    title.backgroundColor = LEBackgroundColor;
    switch (section) {
        case 0:
            title.text = @"  订单详情";
            break;
        case 1:
            title.text = @"  投诉商品";
            break;
        case 2:
            title.text = @"  投诉详情";
            break;
        case 3:
            title.text = @"  申诉详情";
            break;
            
        default:
            break;
    }
    return title;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
       LEReplyToupleCell *cell = [tableView dequeueReusableCellWithIdentifier:LEReplyToupleCellId forIndexPath:indexPath];
        [cell loadData:self.model indexPath:indexPath];
        return cell;
    }
    if (indexPath.section == 1)
    {
        LEGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:LEGoodsCellId forIndexPath:indexPath];
        cell.model = self.model.goodsModelArray[indexPath.row];
        return cell;
    }
    if (indexPath.section == 2)
    {
        if (indexPath.row == 3)
        {
            LEReplyContentCell *cell= [tableView dequeueReusableCellWithIdentifier:LEReplyContentCellId forIndexPath:indexPath];
            cell.model = self.model;
            return cell;
        }
        LEReplyToupleCell *cell = [tableView dequeueReusableCellWithIdentifier:LEReplyToupleCellId forIndexPath:indexPath];
        [cell loadData:self.model indexPath:indexPath];
        return cell;
    }
    LERemarkCell *cell = [tableView dequeueReusableCellWithIdentifier:LERemarkCellId forIndexPath:indexPath];
    [cell.goExplainButton addTarget:self action:@selector(goExplain) forControlEvents:UIControlEventTouchUpInside];
    if ([self.model.complain_state isEqualToString:@"20"])
    {
        cell.goExplainButton.hidden = NO;
        cell.explainLabel.hidden = YES;
    }else{
        cell.goExplainButton.hidden = YES;
        cell.explainLabel.hidden = NO;
        cell.explainLabel.text = self.model.appeal_message;
    }
    
    return cell;
}
#pragma mark- 点击事件
- (void)goExplain
{
    LELog(@"%s---%d---去申诉",__func__,__LINE__);
    LEExplainContentController *explain = [[LEExplainContentController alloc] init];
    explain.explainMode = Remark;
    explain.complain_id = self.model.complain_id;
    [self.navigationController pushViewController:explain animated:YES];
}
- (void)refreshRemarkContent:(NSNotification *)notification
{
    NSString *remarkString = notification.object;
    self.model.complain_state = @"40";
    self.model.appeal_message = remarkString;
    [self.tableView reloadData];
}
@end
